package com.xjh.mange.vo;


import com.xjh.mange.common.enums.ResponseEnum;
import lombok.Data;

/**
 * @author 徐佳辉
 * @date 2020/11/16 15:19
 * <p>
 * 0 成功
 * -1 失败
 */
@Data
public class ResponseVO<T> {

    public static final int successCode = 0;
    private Integer code;

    private String msg;

    private T data;

    private ResponseVO() {

    }

    private ResponseVO(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResponseVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseVO<T> ok() {
        return new ResponseVO<>(successCode, "success");
    }

    public static <T> ResponseVO<T> ok(String msg) {
        return new ResponseVO<>(successCode, msg);
    }

    public static <T> ResponseVO<T> ok(T data) {
        return new ResponseVO<>(successCode, "success", data);
    }

    public static <T> ResponseVO<T> ok(Integer code, String msg, T data) {
        return new ResponseVO<>(code, msg, data);
    }

    public static <T> ResponseVO<T> ok(String msg, T data) {
        return new ResponseVO<>(successCode, msg, data);
    }

    public static <T> ResponseVO<T> error(String message) {
        return new ResponseVO<>(-1, message);
    }

    public static <T> ResponseVO<T> error() {
        return new ResponseVO<>(-1, "fail");
    }

    public static <T> ResponseVO<T> error(Integer code, String msg) {
        return new ResponseVO<>(code, msg);
    }

    public static <T> ResponseVO<T> error(Integer code, String msg, T data) {
        return new ResponseVO<>(code, msg, data);
    }

    public static <T> ResponseVO<T> enums(ResponseEnum responseEnum) {
        return new ResponseVO<>(responseEnum.getCode(), responseEnum.getMsg(), null);
    }

}
